package com.wires.lu.practice;


import java.util.concurrent.TimeUnit;

public class RocketMqDelayDemo {


    public static void main(String[] args) throws Exception {

       // for(int i=0;i<1000;i++){
            new Thread(()->{
                Integer waittime=105;
                long l = System.currentTimeMillis();
                try {
                    senMsg( WaitTimeEnum.getObjectByTime(waittime),0);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                long l1 = System.currentTimeMillis();
                System.out.println(l1-l);
            }).start();
        //}
    }

    public static void senMsg(WaitTimeEnum waitTimeEnum,Integer next) throws InterruptedException {
        Integer size=waitTimeEnum.getLevelList().size();
        Integer waitTime=waitTimeEnum.getLevelList().get(next);
        TimeUnit.SECONDS.sleep(waitTime);
        if(next==(size-1)){
            System.out.println("发送最终消息");
            luojiComein();
        }else if(next<= (size-2)){
            //需要发送另一次生产消息
            System.out.println("需要发送另一次生产消息");
            senMsg(waitTimeEnum,next+1);
        }
    }

    public static void consumerMsg(WaitTimeEnum  waitTimeEnum,Integer next) throws InterruptedException {
        Integer size=waitTimeEnum.getLevelList().size();
        Integer waitTime=waitTimeEnum.getLevelList().get(next);
        TimeUnit.SECONDS.sleep(waitTime);
        if(next==(size-1)){
            System.out.println("发送最终消息");
            luojiComein();
        }else if(next<= (size-2)){
            //需要发送另一次生产消息
            System.out.println("需要发送另一次生产消息");
            senMsg(waitTimeEnum,next+1);
        }
    }

    public static void luojiComein(){
        System.out.println("执行后面的业务逻辑");
    }


}
